<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Reflect</title>
</head>
<body>
    <script>
        let obj = {
            name: '石兴龙'
        }
        // try {
        //     Object.defineProperty(obj, "age", {
        //         enumerable: false,
        //         configurable: false,
        //         writable: false,
        //         value: 18
        //     });
        // } catch (error) {
            
        // }
        // let p = new Proxy(obj, {
        //     defineProperty: (target, key, value, t) => {
        //         target[key] = value.value
        //         return true
        //     }
        // })
        
        let res = Reflect.defineProperty(p, "age", {
            value: 18
        })

        // 对象表达式函数化
        console.log(
            // 'age' in obj
            Reflect.has(obj, 'name')
        )

        // Proxy 和 Reflect

        let o = {
            name: '石兴龙'
        }
        let p = new Proxy(o, {
            // 代理: 获取属性
            get: (target, key) => {
                return Reflect.get(target, key)
            },
            // 代理: 属性设置
            set: (target, key, val) => {
                return Reflect.set(target, key, val)
            },
            // 代理: 删除 key
            deleteProperty: (target, key) => {
                return Reflect.deleteProperty(target, key)
            },
        })
        console.log(p.name)
        p.name = 'test _ 123'
        delete p.name
        console.log(p)

    </script>
</body>
</html>